package network.udp.udp_group;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-26 16:06
 **/
public class GroupSend {
    public static void main(String[] args) {
        send();

    }

    private static void send() {
        DatagramSocket ds = null;
        try {
            //创建socket
            ds = new DatagramSocket();

            //创建发送包
            byte[] bytes = "发送的数据".getBytes();
            //组播地址接收
            DatagramPacket p = new DatagramPacket(bytes, bytes.length
                    , InetAddress.getByName("224.0.0.1"), 10000);
            // SocketAddress socketAdd = InetSocketAddress.createUnresolved("", 10);
            // DatagramPacket p2 = new DatagramPacket(bytes, bytes.length
            //         , socketAdd);

            //发送
            ds.send(p);
            //释放资源
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (ds != null) {
                ds.close();
            }
        }
    }
}
